﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using BAL.Entities;
using DAL.SQLStatements;
using System.Data;
using BAL.Utils;

namespace DAL.LogicComponents
{
    public class clsCategoryDAL
    {
        #region --- Category
        public static bool queryAddCategory(clsCategory obj)
        {
            // Add value to column(s)
            Dictionary<String, Object> data = new Dictionary<String, Object>();
            data.Add("colCategory", "N'" + obj.CategoryName + "'");
            data.Add("colDescription", "N'" + obj.Description + "'");
            data.Add("colInsertDate", "'"+clsDateTimeSetting.UTCTime()+"'");
            data.Add("colIsTrash", 1);

            //Execute insert query
            clsQueryBuilder query = new clsQueryBuilder();
            return query.executeInsertInto("tblCategory", data);
        }
        #endregion

        #region --- select category list
        public static DataTable querySelectCategoryList()
        {
            clsQueryBuilder query = new clsQueryBuilder();
            query.propTable = "tblCategory";
            query.propColumn = "*";
            query.propWhere = "colIsTrash = 1";

            return query.getDatatable();
        }
        #endregion ---

        #region --- select category list by id
        public static DataTable querySelectCategoryListByID(clsCategory obj)
        {
            clsQueryBuilder query = new clsQueryBuilder();
            query.propTable = "tblCategory";
            query.propColumn = "*";
            query.propWhere = "colIsTrash = 1 and colCategoryID ='"+obj.CategoryID+"'";

            return query.getDatatable();
        }
        #endregion

        #region --- update category
        public static bool queryUpdateCategory(clsCategory obj)
        {
            Dictionary<String, Object> cols = new Dictionary<String, Object>();
            cols.Add("colCategory", obj.CategoryName);
            cols.Add("colDescription", obj.Description);
            cols.Add("colLastUpdate", "'" + clsDateTimeSetting.UTCTime() + "'");
            // Execute update query
            clsQueryBuilder query = new clsQueryBuilder();
            return query.executeUpdate("tblCategory", cols, String.Format("colCategoryID = {0}", obj.CategoryID));

        }
        #endregion
    }
}